$(document).ready(function(){
    findAllRole();
    //黎肇明
    $("#dialog").dialog("destroy");
    $("#dialog-form").dialog({
        autoOpen: false,
        width: 460,
        modal: true,
        resizable: false,
        close: function(){
            $("#user-form input").removeClass('invalid');
            $("#user-form label").remove('.invalid');
            //getPaList();
            //return false;
            $("dialog").dialog("close");
        }
    });
    $('#saveRoleBtn').click(function(){
        $('#dialog-form').dialog('open');
    });
});

function findAllRole(){
    $.ajax({
        type: "post",
        url: "admin/Role_findAllRole.action",
        success: showData
    });
}

function showData(data){
    $("#listRole").empty().hide();
    $("#noneRole").hide();
    $("#loadingRole").hide();
    $.each(data.roles, function(i, n){
        fillDataToHtml(n.RId, n.RName);
    });
    $("#listRole").show();
    $('.editDIV').click(function(){
        setCookie(RId, $(this).next().text());
        setCookie(RName, $(this).next().next().text());
        window.location.href = "role_pmsn_tree.jsp";
    });
    $('.delDIV').click(function(){
        alert("查看详情");
    });
}

function fillDataToHtml(rid, rName){
    var strHtml = "<tr>";
    strHtml += "<td><div><input name='read' type='radio' /></div></td>";
    strHtml += "<td ><div>" + rName + "</div></td>";
    strHtml += "<td ><div class='editDIV'>分配权限</div><span style='display:none'>";
    strHtml += rid;
    strHtml += "</span><span style='display:none'>"
    strHtml += rName;
    strHtml += "</span></td>";
    strHtml += "<td ><div class='delDIV'>查看详情</div><span style='display:none'>";
    strHtml += rid;
    strHtml += "</span><span style='display:none'>"
    strHtml += rName;
    strHtml += "</span</td>";
    strHtml += "</tr>";
    $("#listRole").append(strHtml);
}

function closeDlg(){
    $("#dialog-form").dialog("close");
    disRst("添加角色成功");
    findAllRole();
}

function disRst(ctn){
    $('#rstSP').show("slow");
    $('#rstSP').text(ctn);
    setTimeout(hiedRst, 3000);
}

function hiedRst(){
    $('#rstSP').hide("slow");
}
